/**
 * @param {number[][]} img
 * @return {number[][]}
 */
var imageSmoother = function (img) {
  let row = img.length,
    col = img[0].length
  let arr = new Array(row).fill(0).map(() => new Array(col).fill(0))
  for (let i = 0; i < row; i++) {
    for (let j = 0; j < col; j++) {
      let count = 0,
        sum = 0
      for (let x = i - 1; x <= i + 1; x++) {
        for (let y = j - 1; y <= j + 1; y++) {
          if (x >= 0 && x < row && y >= 0 && y < col) {
            count++
            sum += img[x][y]
          }
        }
      }

      arr[i][j] = Math.floor(sum / count)
    }
  }

  return arr
}
imageSmoother([
  [100, 200, 100],
  [200, 50, 200],
  [100, 200, 100],
])
